import StructureCache, { RegisterStructure } from '@/modules/structureCache'
import HarvestTaskManager from '@/room/task/base/harvest'
import MineTaskManager from '@/room/task/base/mine'
import UpgradeTaskManager from '@/room/task/base/upgrade'

/**
 * 容器控制器
 */
export default class ContainerController {
    protected static registerFns: RegisterStructure<STRUCTURE_CONTAINER>[] = [
        HarvestTaskManager.registerContainer,
        UpgradeTaskManager.registerContainer,
        MineTaskManager.registerContainer,
    ]

    /**
     * 注册 container
     */
    public static registerContainer(room: MyRoom, containers: StructureContainer[]) {
        ContainerController.registerFns.forEach((fn) => (containers = fn(room, containers)))
    }

    /**
     * 挂载
     */
    public static mount() {
        StructureCache.onNewStruct(function registerContainer(room, newStructMap) {
            const containers = newStructMap[STRUCTURE_CONTAINER]
            if (containers) ContainerController.registerContainer(room, containers)
        })
    }
}
